package com.demo.supplier.constant;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * API常量配置类
 * 
 * @author demo
 */
@Component
public class ApiConstants {

    /**
     * API前缀
     */
    @Value("${api.prefix:/api/v1}")
    private String apiPrefix;

    /**
     * API版本
     */
    @Value("${api.version:v1}")
    private String apiVersion;

    /**
     * 获取API前缀
     */
    public String getApiPrefix() {
        return apiPrefix;
    }

    /**
     * 获取API版本
     */
    public String getApiVersion() {
        return apiVersion;
    }

    /**
     * 构建完整的API路径
     */
    public String buildApiPath(String path) {
        if (path.startsWith("/")) {
            return apiPrefix + path;
        }
        return apiPrefix + "/" + path;
    }

    /**
     * 获取认证登录路径
     */
    public String getLoginPath() {
        return buildApiPath(AUTH + "/login");
    }

    /**
     * 获取认证登出路径
     */
    public String getLogoutPath() {
        return buildApiPath(AUTH + "/logout");
    }

    /**
     * 获取通用API匹配模式
     */
    public String getApiPattern() {
        return apiPrefix.substring(0, apiPrefix.lastIndexOf('/')) + "/**";
    }

    // API路径常量
    public static final String SUPPLIERS = "/suppliers";
    public static final String USERS = "/users";
    public static final String AUTH = "/auth";
    public static final String FILES = "/files";
    public static final String LOGS = "/logs";
}